package com.行为型模型.P责任链模式;

/**
 * 处理者抽象类 责任链节点
 */
public abstract class Handler {

    protected final static int NUM_1=1;
    protected final static int NUM_3=3;
    protected final static int NUM_7=7;

    //该领导处理的请假天数区间
    private int numStart;
    private int numEnd;
    //领导上面还有领导  自己聚合自己
    private Handler nextHandler;
    //设置请假天数范围 上不封顶    
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }
    //设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }
    //提交请假条
    public final void submit(LeaveRequest leaveRequest){
        if (0==this.numStart){
            return;
        }
        //如果请假天数达到该领导者的处理请求
        if (leaveRequest.getNum()>=this.numStart){
            this.handleLeave(leaveRequest);

            //如果还有上级，并且请假天数超过了当前领导的处理范围
            if (null != this.nextHandler && leaveRequest.getNum()>numEnd){
                this.nextHandler.submit(leaveRequest);
            }else{
                System.out.println("流程结束");
            }



        }


    }

    //各级领导处理请假条方法，设为抽象，由各自实现
    protected abstract void handleLeave(LeaveRequest leaveRequest);



}
